#pragma once

#include <string>
#include <mutex>

// 前置声明 C API
extern "C" {
#include <neo4j-client.h>
}

class DbClient {
public:
    // 获取单例实例（首次调用需提供 URI）
    static DbClient& getInstance(const std::string& uri = "", bool insecure = true);

    ~DbClient();

    // 禁止拷贝和移动
    DbClient(const DbClient&) = delete;
    DbClient& operator=(const DbClient&) = delete;
    DbClient(DbClient&&) = delete;
    DbClient& operator=(DbClient&&) = delete;

    // 执行 Cypher 查询
    neo4j_result_stream_t* run(const char *cypher, neo4j_value_t params = neo4j_null);

    neo4j_connection_t* connection_ = nullptr;
private:
    // 私有构造函数
    DbClient(const std::string& uri, bool insecure);

    // 连接与断开连接
    void connect();
    void close();

    std::string uri_;
    bool insecure_;

    // 单例相关
    static DbClient* instance_;
    static std::mutex mutex_;
};